<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://eureka.yigolden.net/stringutils/sutaglib/1.0" prefix="su"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
<title>查询药品</title>

  <!-- Bootstrap -->
    <link href="<%=request.getContextPath()%>/static/css/bootstrap.min.css" rel="stylesheet">
    <link href="<%=request.getContextPath()%>/static/css/bootstrap-theme.min.css" rel="stylesheet">
    <link href="<%=request.getContextPath()%>/static/css/jumbotron.css" rel="stylesheet">
    
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="<%=request.getContextPath()%>/static/js/html5shiv.min.js"></script>
      <script src="<%=request.getContextPath()%>/static/js/respond.min.js"></script>
    <![endif]-->
    
    
</head>
<body>

    <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="<%=request.getContextPath()%>/">本草纲目网</a>
        </div>
        
        <c:if test="${user eq null }">
        <div id="navbar" class="navbar-collapse collapse">
          <form class="navbar-form navbar-right" method="post" action="<%=request.getContextPath()%>/Account/Login">
            <input type="hidden" name="action" value="login" />
            <div class="form-group">
              <input type="text" placeholder="账户" name="username" class="form-control">
            </div>
            <div class="form-group">
              <input type="password" placeholder="密码" name="password" class="form-control">
            </div>
            <button type="submit" class="btn btn-success">立即登陆</button>
            <a class="btn btn-info" href="<%=request.getContextPath() %>/Account/Register">马上注册</a>
          </form>
        </div><!--/.navbar-collapse -->
		</c:if>
		<c:if test="${user ne null }">
		<div id="navbar" class="navbar-collapse collapse">
		  <ul class="nav navbar-nav navbar-right">
		    <li><a>欢迎您，<b>${fn:escapeXml(user.realName) }</b>！</a></li>
		    <li><a href="<%=request.getContextPath() %>/Order/ShowMyOrders">我的订单</a></li>
		    <li><a href="<%=request.getContextPath() %>/Cart/ShowMyCart">我的购物车</a></li>
		    <li><a href="<%=request.getContextPath() %>/Account/Logout">注销</a></li>
		  </ul>
  		</div>
		</c:if>

      </div>
    </nav>

<div class="container">

<div class="row" style="text-align:center;margin-top:51px;">
         <img src="<%=request.getContextPath()%>/static/image/title.jpg" width="310px" height="152"/>
      </div>
      <br/>
      <br/>
       
      <div class="row">
          <div class="col-lg-3 col-sm-2"></div><!--左侧不用-->
          <div class="col-lg-6 col-sm-8 col-xs-12">
          <form method="get">
           <div class="input-group">
             <input type="text" class="form-control" name="keyword" placeholder="检索药品……" value="${fn:escapeXml(param.keyword) }">
             <span class="input-group-btn">
                  <button class="btn btn-default" type="submit">查询药品</button>
             </span>
           </div><!-- /input-group -->
            </form>
         </div><!-- /.col-sm-4 -->
         <div class="col-lg-3 col-sm-2"></div><!--右侧不用-->
      </div>
       
      <br/>
      <br/>   
      
	  <div class="row">
      <div class="col-sm-2"></div><!--左侧不用-->
      
      <div class="col-sm-8 col-xs-12">
	  
	  <c:set var="i" value="0" />
      <c:if test="${page ne null }">

      <c:if test="${page.countAll ne 0 }">

	  <div class="table-responsive">
	    <table class="table table-hover table-stripped">
		  <tr style="background:aliceblue">
		    <td style="min-width:60px">名称</td>
		   
		    <td style="min-width:60px">
                  <c:choose>
                  <c:when test="${param.orderBy eq 1 }">
                   <c:choose>
                    <c:when test="${param.orderByType eq 1 }">
                     <a href="?keyword=${keywordEncoded }&orderBy=1&orderByType=2" class="nav2hightlight">价格↑</a>
                    </c:when>
                    <c:when test="${param.orderByType eq 2 }">
                     <a href="?keyword=${keywordEncoded }" class="nav2hightlight">价格↓</a>
                    </c:when>
                    <c:otherwise>
                     <a href="?keyword=${keywordEncoded }&orderBy=1&orderByType=1">价格</a>
                    </c:otherwise>
                   </c:choose>
                  </c:when>
                  <c:otherwise>
                   <a href="?keyword=${keywordEncoded }&orderBy=1&orderByType=1">价格</a>
                  </c:otherwise>
                 </c:choose>
		    </td>
		    <td style="min-width:60px">
                  <c:choose>
                  <c:when test="${param.orderBy eq 2 }">
                   <c:choose>
                    <c:when test="${param.orderByType eq 1 }">
                     <a href="?keyword=${keywordEncoded }&orderBy=2&orderByType=2" class="nav2hightlight">库存↑</a>
                    </c:when>
                    <c:when test="${param.orderByType eq 2 }">
                     <a href="?keyword=${keywordEncoded }" class="nav2hightlight">库存↓</a>
                    </c:when>
                    <c:otherwise>
                     <a href="?keyword=${keywordEncoded }&orderBy=1&orderByType=1">库存</a>
                    </c:otherwise>
                   </c:choose>
                  </c:when>
                  <c:otherwise>
                   <a href="?keyword=${keywordEncoded }&orderBy=2&orderByType=1">库存</a>
                  </c:otherwise>
                 </c:choose>
		    </td>
		   
		    <td>描述</td>
		  </tr>
		  
		  <c:set var="i" value="0" />
		  <c:forEach var="item" items="${page.records}">
		    <c:set var="i" value="${i + 1 }" />
			<tr>
			  <td><a href="ShowGoodItem?id=${item.id }" target="_blank">${fn:escapeXml(item.name) }</a></td>
			  <td>${fn:escapeXml(item.price) }</td>
			  <td>${fn:escapeXml(item.inventory) }</td>
			  <td>${fn:escapeXml(item.description) }</td>
			</tr>
		  </c:forEach>
		</table>
	  </div>
	  
	  
	  <br/>
	  
      <div class="row" style="text-align:center;">
      <nav> 
          <ul class="pagination">
          <c:choose>
		    <c:when test = "${page.hasPrevious}">
		    <li><a href="?keyword=${keywordEncoded}&curPage=1&pageSize=${page.pageSize}&orderBy=${su:encodeUriComponent(param.orderBy)}&orderByType=${su:encodeUriComponent(param.orderByType)}"><span aria-hidden="true">&laquo;</span></a></li>
            <li><a  href="?keyword=${keywordEncoded}&curPage=${page.prePage}&pageSize=${page.pageSize}&orderBy=${su:encodeUriComponent(param.orderBy)}&orderByType=${su:encodeUriComponent(param.orderByType)}"><span aria-hidden="true">&lt;</span></a></li>
		    </c:when>
		    <c:otherwise>
		    <li class="disabled"><a href="#" onclick="return false;"><span aria-hidden="true">&laquo;</span></a></li>
		    </c:otherwise>
		    </c:choose>
		     
		    <c:if test="${page.currentPage-3 gt 0}">
            <li><a href = "?keyword=${keywordEncoded}&curPage=${page.currentPage-3}&pageSize=${page.pageSize}&orderBy=${su:encodeUriComponent(param.orderBy)}&orderByType=${su:encodeUriComponent(param.orderByType)}">${page.currentPage-3}</a></li>
            </c:if>
            <c:if test="${page.currentPage-2 gt 0}">
            <li><a href = "?keyword=${keywordEncoded}&curPage=${page.currentPage-2}&pageSize=${page.pageSize}&orderBy=${su:encodeUriComponent(param.orderBy)}&orderByType=${su:encodeUriComponent(param.orderByType)}">${page.currentPage-2}</a></li>
            </c:if>
            <c:if test="${page.currentPage-1 gt 0}">
            <li><a href = "?keyword=${keywordEncoded}&curPage=${page.currentPage-1}&pageSize=${page.pageSize}&orderBy=${su:encodeUriComponent(param.orderBy)}&orderByType=${su:encodeUriComponent(param.orderByType)}">${page.currentPage-1}</a></li>
            </c:if>
            <li class="active"><a href="#">${page.currentPage}</a></li>
             
             <c:if test="${page.maxPage - page.currentPage -0 gt 0}">
            <li><a href = "?keyword=${keywordEncoded}&curPage=${page.currentPage+1}&pageSize=${page.pageSize}&orderBy=${su:encodeUriComponent(param.orderBy)}&orderByType=${su:encodeUriComponent(param.orderByType)}">${page.currentPage+1}</a></li>
            </c:if>
            <c:if test="${page.maxPage - page.currentPage -1 gt 0}">
            <li><a href = "?keyword=${keywordEncoded}&curPage=${page.currentPage+2}&pageSize=${page.pageSize}&orderBy=${su:encodeUriComponent(param.orderBy)}&orderByType=${su:encodeUriComponent(param.orderByType)}">${page.currentPage+2}</a></li>
            </c:if>
            <c:if test="${page.maxPage - page.currentPage -2 gt 0}">
            <li><a href = "?keyword=${keywordEncoded}&curPage=${page.currentPage+3}&pageSize=${page.pageSize}&orderBy=${su:encodeUriComponent(param.orderBy)}&orderByType=${su:encodeUriComponent(param.orderByType)}">${page.currentPage+3}</a></li>
            </c:if>

            <c:choose>
		    <c:when test = "${page.hasNext}">
            <li><a href="?keyword=${keywordEncoded}&curPage=${page.nextPage}&pageSize=${page.pageSize}&orderBy=${su:encodeUriComponent(param.orderBy)}&orderByType=${su:encodeUriComponent(param.orderByType)}"><span aria-hidden="true">&gt;</span></a></li>
            <li><a href="?keyword=${keywordEncoded}&curPage=${page.maxPage}&pageSize=${page.pageSize}&orderBy=${su:encodeUriComponent(param.orderBy)}&orderByType=${su:encodeUriComponent(param.orderByType)}"><span aria-hidden="true"> &raquo; </span></a></li>
		    </c:when>
		    <c:otherwise>
		    <li class="disabled"><a href="#" onclick="return false;"><span aria-hidden="true">&raquo;</span></a></li>
		    </c:otherwise>
		    </c:choose>    
         </ul>
      </nav>
      </div>
	  
      </c:if>

	  
      <c:if test="${i eq 0 }">
        <div class="alert alert-warning" role="alert">不好意思，没有搜索结果！</div>
      </c:if>
      
      </c:if>
      
      </div>
      <div class="col-sm-2"></div><!--右侧不用-->
    </div>
 
    <footer style="padding-top:19px;color:#777;border-top:1px solid #e5e5e5">
      <p>&copy; 2016 中国药科大学理学院信息管理与信息系统13480班第3组</p>
    </footer>

</div>

 <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="<%=request.getContextPath()%>/static/js/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="<%=request.getContextPath()%>/static/js/bootstrap.min.js"></script>

</body>
</html>